import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import Rbf

# 定义数据点
x = np.array([-1, 0, 2.0, 1.0])
y = np.array([1.0, 0.3, -0.5, 0.8])

# 生成加密点
xi = np.linspace(-3, 4, 100)

# 创建RBF插值函数
rbf_multiquadric = Rbf(x, y, function='multiquadric')
rbf_gaussian = Rbf(x, y, function='gaussian')
rbf_linear = Rbf(x, y, function='linear')

# 使用RBF插值函数计算加密点的值
yi_multiquadric = rbf_multiquadric(xi)
yi_gaussian = rbf_gaussian(xi)
yi_linear = rbf_linear(xi)

# 绘制原始数据点和插值结果
plt.figure(figsize=(14, 5))

# 绘制multiquadric插值结果
plt.subplot(1, 3, 1)
plt.plot(xi, yi_multiquadric, label='multiquadric')
plt.scatter(x, y, color='red', label='Data Points')
plt.title('Multiquadric')
plt.legend()

# 绘制gaussian插值结果
plt.subplot(1, 3, 2)
plt.plot(xi, yi_gaussian, label='gaussian')
plt.scatter(x, y, color='red', label='Data Points')
plt.title('Gaussian')
plt.legend()

# 绘制linear插值结果
plt.subplot(1, 3, 3)
plt.plot(xi, yi_linear, label='linear')
plt.scatter(x, y, color='red', label='Data Points')
plt.title('Linear')
plt.legend()

plt.tight_layout()
plt.show()